local t=Def.ActorFrame{};

local lifeWidth=SCREEN_WIDTH/4;

local lighteff=GetUserPref_Theme("UserLightEffect");
local haishin=GetUserPref_Theme("UserHaishin");

local song;
local eff_st;
local now = 0.0;
local player_l=GetSidePlayer(PLAYER_1);
local player_r=GetSidePlayer(PLAYER_2);
local beat_l;
local beat_r;
local now_l;
local now_r;
local sample=0;
local sample_l;
local sample_r;

local function SongChk()
	local ret=false;
	if (not song) or (song ~= _SONG2()) then
		song = _SONG2();
		eff_st = song:GetSampleStart();
		sample_l=math.round(GetPlayerSongBeat2(player_l,eff_st));
		sample_r=math.round(GetPlayerSongBeat2(player_r,eff_st));
		ret=true;
	end;
	now=_MUSICSECOND();
	now_l = GetPlayerSongBeat2(player_l,now);
	beat_l = (haishin=="On") and 0.0001 or 0.1*(now_l*10%10);
	now_r = GetPlayerSongBeat2(player_r,now);
	beat_r = (haishin=="On") and 0.0001 or 0.1*(now_r*10%10);
	return ret;
end;

local chksec=0.025;
t[#t+1]=Def.ActorFrame{
	OnCommand=function(self)
		self:sleep(0.75);
		self:queuecommand("Loop");
	end;
	LoopCommand=function(self)
		local ret=SongChk();
		self:finishtweening();
		self:visible(true);
		self:sleep(chksec);
		self:queuecommand("Loop");
	end;

	LoadActor(THEME:GetPathG("_LifeMeterBar/LifeMeterBar","Effect"))..{
		Name="BIG_TL";
		InitCommand=cmd(horizalign,right;vertalign,top;x,SCREEN_CENTER_X-lifeWidth-lifeWidth/4-SCREEN_WIDTH/16+40;
			y,SCREEN_TOP-10;blend,"BlendMode_Add";);
		OnCommand=cmd(diffusealpha,0;addy,-100;sleep,0.5;linear,0.25;addy,100;);
		OffCommand=cmd(diffusealpha,1;sleep,0.25;linear,0.25;addy,-100;diffusealpha,0);
		LoopCommand=function(self)
			if (now_l>=sample_l and (lighteff=='Auto')) or (lighteff=='Always') then
				self:diffusealpha(1-beat_l);
			else
				self:diffusealpha(0);
			end;
		end;
		};
	LoadActor(THEME:GetPathG("_LifeMeterBar/LifeMeterBar","Effect"))..{
		Name="BIG_TR";
		InitCommand=cmd(horizalign,right;vertalign,top;x,SCREEN_CENTER_X+lifeWidth+lifeWidth/4+SCREEN_WIDTH/16-40;
			y,SCREEN_TOP-10;rotationy,180;blend,"BlendMode_Add";);
		OnCommand=cmd(diffusealpha,0;addy,-100;sleep,0.5;linear,0.25;addy,100;);
		OffCommand=cmd(diffusealpha,1;sleep,0.25;linear,0.25;addy,-100;diffusealpha,0);
		LoopCommand=function(self)
			if (now_r>=sample_r and (lighteff=='Auto')) or (lighteff=='Always') then
				self:diffusealpha(1-beat_r);
			else
				self:diffusealpha(0);
			end;
		end;
	};
	LoadActor(THEME:GetPathG("_LifeMeterBar/LifeMeterBar","Effect"))..{
		Name="BIG_BL";
		InitCommand=cmd(horizalign,right;vertalign,top;x,SCREEN_CENTER_X-lifeWidth-lifeWidth/4-SCREEN_WIDTH/16+40;
			y,SCREEN_BOTTOM+10;rotationx,180;blend,"BlendMode_Add";);
		OnCommand=cmd(diffusealpha,0;addy,100;sleep,0.5;linear,0.25;addy,-100;);
		OffCommand=cmd(diffusealpha,1;sleep,0.25;linear,0.25;addy,100;diffusealpha,0);
		LoopCommand=function(self)
			if (now_l>=sample_l and (lighteff=='Auto')) or (lighteff=='Always') then
				self:diffusealpha(1-beat_l);
			else
				self:diffusealpha(0);
			end;
		end;
	};
	LoadActor(THEME:GetPathG("_LifeMeterBar/LifeMeterBar","Effect"))..{
		Name="BIG_BR";
		InitCommand=cmd(horizalign,right;vertalign,top;x,SCREEN_CENTER_X+lifeWidth+lifeWidth/4+SCREEN_WIDTH/16-40;
			y,SCREEN_BOTTOM+10;rotationx,180;rotationy,180;blend,"BlendMode_Add";);
		OnCommand=cmd(diffusealpha,0;addy,100;sleep,0.5;linear,0.25;addy,-100;);
		OffCommand=cmd(diffusealpha,1;sleep,0.25;linear,0.25;addy,100;diffusealpha,0);
		LoopCommand=function(self)
			if (now_r>=sample_r and (lighteff=='Auto')) or (lighteff=='Always') then
				self:diffusealpha(1-beat_r);
			else
				self:diffusealpha(0);
			end;
		end;
	};
};

return t;
